#include "grate_test_utils.h"
#include "grate/util/bit_vector.h"

using growth_rate::BitVector;

namespace {

TEST(BitVector, DifferentSizes) {
  for (size_t size = 1; size <= 16; size++) {
    BitVector vector(size);
    // Set and unset all items one by one.
    for (size_t item = 0; item < size; item++) {
      EXPECT_FALSE(vector.get(item));
      vector.set(item, true);
      EXPECT_TRUE(vector.get(item));
      vector.set(item, false);
      EXPECT_FALSE(vector.get(item));
    }
  }
}

TEST(BitVector, StressTest) {
  const size_t kSize = 10;
  const size_t kIterations = 1000;
  BitVector vector(kSize);
  bool array[kSize] = { false };
  for (size_t iter = 0; iter < kIterations; iter++) {
    size_t index = random(kSize);
    bool value = (random(2) == 0);
    vector.set(index, value);
    array[index] = value;
    for (size_t i = 0; i < kSize; i++)
      EXPECT_EQ(array[i], vector.get(i));
  }
}

}  // namespace

